{include file="./headStart.tpl"}
<head>
<script type="text/javascript" src="./js/jquery.colorbox.js"></script>
<script type="text/javascript" src="./js/Modal.js"></script>
<link media="screen" rel="stylesheet" href="./css/colorbox.css" />
<link rel="stylesheet" type="text/css" href="./css/SModal.css">
{literal}
<script type="text/javascript">
$(document).ready(function() {
  $("#productHide").hide();  
  $(".partyId").change(function(){
  var dataString = "partyId=" + $(".partyId").val();
	 $.ajax({ 
     type: "GET",
     url:  "partyAddressAj.php",
     data: dataString,
     success: function(data){
     $("#addressType").val(data);
    }
  });
  });

// Party On Change Supplier Address 
  $(".supplierId").change(function(){
  var dataString = "supplierId=" + $(".supplierId").val();
	 $.ajax({ 
     type: "GET",
     url:  "supplierddressAj.php",
     data: dataString,
     success: function(data){
     $("#addressType").val(data);
    }
  });
});

  // To change subcategory : Starts
  $(".classSubcategory").change(function(){
    subCategoryCombo($(this));
  });
  // To change subcategory : End
 $(".add").click(function(){ 
   $("#one").clone(true).appendTo("#mainDiv").find('input[type="text"]').val('');    
   addRow();
  });
  $("#srNoInsert").blur(function() {
    srnoMatch($(this));
  });  
});

function formvalidation()
{
	var data0 = $(".classSubcategory:last").val();
	var data1 = $(".itemIdClass:last").val();
	var data2 = $(".netQuantityUsed:last").val();
	
     if(data0 == 0)
     {
       alert("Please select any Sub Category");
       $(".itemIdClass").focus();
       return false;
     }
     if(data1 == 0)
     {
       alert("Please select any Product");
       $(".itemIdClass").focus();
       return false;
     }
     if(data2 == '')
     {
       alert("Net Quantity is blank");
       $(".netQuantityUsed").focus();
       return false;
     }
}
function deleteRow()
{
  $('.delete').click(function()
  {
    var countSr = 1;
    $(this).parent().parent().remove();
    $('.srNoClass').each(function(){
          this.value = countSr++;
        });
    return false;
  });
}
function addRow() 
{
  var countSr = 1;
  $('.srNoClass').each(function()
  {
    this.value = countSr++;
  });
  return false;
}
// To change item : Starts
function subCategoryCombo(itemObj)
{
  var rowCount = 0;
  $('.classSubcategory').each(function()
  {
    rowCount++;
  });
    var dataString1 = "subCategoryId=" + $(itemObj).val() +"&rowCount=" + rowCount; 
  
  $.ajax({
    url: "./itemAj.php",
    cache: false,
    data: dataString1,
    success:function(data){
    	$(itemObj).next("span").html(data);
    	$(itemObj).focus();
    	$("#productHide").show();
    	
      jQuery('.addItem').colorbox({maxWidth: '75%', onComplete: function(){
        jQuery("#itemAddAj").submit(function(){
        	var itemNameVar = $("#itemName").val();
          jQuery.post(
            jQuery(this).attr('action'),
            jQuery(this).serialize(),
            function(data){
            	$("<option value='"+data+"' SELECTED>"+itemNameVar+"</option>").appendTo("#itemId"+rowCount);
              $.colorbox.close();
            }
          );
         return false;
       });
      }});    
    }
  });
}

function subCategoryComboEdit(subCategoryId,rowCount,itemIdSelected)
{
  var dataString1 = "subCategoryId=" + subCategoryId + "&rowCount=" + rowCount + "&itemIdSelected=" + itemIdSelected;
  $.ajax({
    url: "./itemAj.php",
    cache: false,
    data: dataString1,
    success:function(data){
    	$("#subCategoryId"+rowCount).next("span").html(data);
    //	$("#productHide").show();
    	
      jQuery('.addItem').colorbox({maxWidth: '75%', onComplete: function(){
        jQuery("#itemAddAj").submit(function(){
        	var itemNameVar = $("#itemName").val();
          jQuery.post(
            jQuery(this).attr('action'),
            jQuery(this).serialize(),
            function(data){
            	$("<option value='"+data+"' SELECTED>"+itemNameVar+"</option>").appendTo("#itemId"+rowCount);
              $.colorbox.close();
            }
          );
         return false;
       });
      }});    
    }
  });
}
function srnoMatch(srObj)
{
	if($(srObj).val() < {/literal}{$srnoSelected}{literal})
	{
		alert("Please Insert max sr no!");
		setTimeout(function(){srObj.focus()}, 1);
	}  
}
// To change item : Ends

</script>
{/literal}
{include file="./headEnd.tpl"}
<form name="form" action="{$smarty.server.PHP_SELF}" id="form" method="post">
<input type="hidden" name="challanShort" id="challan" value="{$challanShort}">
<input type="hidden" name="challanFull" id="challan" value="{$challanType}">
<input type="hidden" name="isEdit" id="challan" value="{$isEdit}">
<table align="center" border="1" cellpadding="2" cellspacing="1" >
<tr>
  <td align="center" class="table1" colspan="6">{$pageHeader}</td>
</tr>
<tr>
	{if $pageHeader == "Goods Inward Note(GIN)" || $pageHeader == "Goods Rejection(GRJ)"}
    <td align="left" class="table2" >Vendor : </td>
  {else}
    <td align="left" class="table2" >Customer: </td>
  {/if}
  <td class="table2">
  	{if $pageHeader == "Goods Inward Note(GIN)" || $pageHeader == "Goods Rejection(GRJ)"}
      <select name="supplierId" class="supplierId">
        <option>Select Name</option>
        {if $isEdit == 1}
          {html_options values=$supplierId output=$companyName selected=$supplierIdSelected onChange="getAddress();"}
        {else}
          {html_options values=$supplierId output=$companyName selected=$lastInserId onChange="getAddress();"}
        {/if}
      </select>
      <a href="supplier.php?redirectFrom=deliveryChalan&challanShort={$challanShort}">New Vendor</a>
    {else}
      <select name="partyId" class="partyId">
        <option>Select Name</option>
        {if $isEdit == 1}
          {html_options values=$partyId output=$firstName selected=$partyIdSelected onChange="getAddress();"}
        {else}                                                                                           
          {html_options values=$partyId output=$firstName selected=$lastInserId onChange="getAddress();"}
        {/if}
      </select>
      <a href="party.php?redirectFrom=deliveryChalan&challanShort={$challanShort}">New Customer</a>
    {/if}
  </td>
  <td align="left" class="table2" >Sr.No.: </td>
  <td class="table2">
    {if $isEdit == 1}
      <input type="text" name="srNo" id="srNo" value="{$srNo}" DISABLED=DISABLED>
     <input type="hidden" class="srNoClass" name="srNoEdit"  value="{$srNo}" size="2">
    {else}
      <input type="text" name="srNoInsert" id="srNoInsert" value="{$srnoSelected}">
    {/if}
  </td>
  <td align="left" class="table2" >Date: </td>
  <td NOWRAP class="table2">
    {html_select_date prefix="delivaryDate" time="$delivaryDateSelected" start_year="-3" end_year="+1" month_format="%m" field_order="DMY" 
     day_value_format="%02d"}
  </td>
</tr>
<tr>
  <td align="left" class="table2">Address : </td>
  {if $pageHeader == 'Delivery Challan/Note(DCN)'}
    <td class="table2" colspan="2"><textarea name="address" rows="4" cols="80" id="addressType">{$addressSelected}</textarea></td>
    <td align="left" class="table2">Material Issued to : </td>
    <td align="left" class="table2" colspan="2">
      <select name="technicianId">
    	  <option value=0>Select Technician </option>
    	  {html_options values=$techName.technicianId output=$techName.firstName selected=$technicianIdSelected}
    	</select>
    </td>
  {else}
    <td class="table2" colspan="5"><textarea name="address" rows="4" cols="80" id="addressType">{$addressSelected}</textarea></td>
  {/if}
</tr>
</table>
</br>
<table align="center" border="1"  cellpadding="1" cellspacing="0">
<tr>
  <td colspan="4"> 
    <table align="center" border="0" id="dataTable" width="100%" cellpadding="1" cellspacing="0">
      <tr>
        <th align="center" class="table1">SR. NO.</th>
        <th align="left" class="table1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sub Category 
          <div style="margin-left:150px;display: inline;border:1px solid black;" id="productHide"> 
            Product
          </div>
        </th>
        <th align="center" class="table1">Desc. of Material</th>
        <th align="center" class="table1">Net Quantity</th>
        {if $challanType ==  "Goods Rejection"}
          <th align="center" class="table1">Remarks</th>
        {/if}
        <th align="center" class="table1">&nbsp;</th>
        <th align="center" class="table1">&nbsp;</th>
      </tr>
      {if $isEdit == 0}
        <tbody id="mainDiv">
        <tr id="one">
          <td class="table2"><input type="text" class="srNoClass" name="srNo[]" id="srNo" value="1" size="2" DISABLED></td>
          <td class="table2" NOWRAP>
            <select name="subCategoryId[]" id="subCategoryId" class="classSubcategory">
          	  <option value=0 >Select Sub Category </option>
          	  {html_options values=$subCategoryName.subCategoryId output=$subCategoryName.subCategoryName}
          	</select>
            <span></span>
          </td>
          <td class="table2"><input type="text" class="descriptionOfMaterial" name="descriptionOfMaterial[]" id="descriptionOfMaterial[]" value="{$descriptionOfMaterial}"></td>
          <td class="table3"><input type="text" class="netQuantityUsed" style="text-align : right"name="netQuantityUsed[]" value="{$quantity}"></td>
          {if $challanType ==  "Goods Rejection"}
            <td class="table2"><input type="text" class="remarks" name="remarks[]"></td>
          {/if}
          <td class="table3"><input type="button" value="Add" name="add" class="add" /></td>
          <td class="table3"><input type="button" value="Delete" name="deleteBtn"  class="delete" onclick="deleteRow()"/></td>
        </tr>
        </tbody>
      {else}
        <tbody id="mainDiv">
          {section name="sec" loop=$detailArr}
          <input type="hidden" name="deliveryChallanMasterId" id="deliveryChallanMasterId" value="{$masterIdSelected}">
          <input type="hidden" name="deliveryChallanDetailId[]" id="deliveryChallanDetailId" value="{$detailArr[sec].deliveryChallanDetailId}">
            <tr id="one">
              <td class="table2">
                <input type="text" class="srNoClass" name="srNo[]" id="srNo[]" value="1" size="2" DISABLED>
              </td>
              <td class="table2" NOWRAP>
                <select name="subCategoryId[]" id="subCategoryId{$smarty.section.sec.rownum}" class="classSubcategory">
              	  <option value=0 >Select Sub Category </option>
              	  {html_options values=$subCategoryName.subCategoryId output=$subCategoryName.subCategoryName selected=$detailArr[sec].subCategoryId}
              	</select>
                <span></span>
              </td>
              <td class="table2"><input type="text" class="descriptionOfMaterial" name="descriptionOfMaterial[]" id="descriptionOfMaterial[]" value="{$detailArr[sec].discription}"></td>
              <td class="table3"><input type="text" class="netQuantityUsed" name="netQuantityUsed[]" value="{$detailArr[sec].quantity}"></td>
              {if $challanType ==  "Goods Rejection"}
                <td class="table2"><input type="text" class="remarks" name="remarks[]"></td>
              {/if}
              <td class="table3"><input type="button" value="Add" name="add" class="add"/></td>
              <td class="table3"><input type="button" value="Delete" name="deleteBtn"  class="delete" onclick="deleteRow()"/></td>
            </tr>
        {/section}
        </tbody>
      {/if}
    </table>
  </td>
</tr>
</table>
<table align="center">
  <tr>
    <td colspan="9">
      {if $isEdit == 1}
        <input class="button" type="submit" value="UPDATE" name="submitBtn" id="submitBtn" onclick="return formvalidation(this);"/>
      {else}
        <input class="button" type="submit" value="SUBMIT" name="submitBtn" id="submitBtn" onclick="return formvalidation(this);"/>
      {/if}
      <input class="button" type="submit" name="printBtn" id="printBtn" value="Print" onclick="return formvalidation(this);" />
      <!--<input type="submit" value="CANCEL" name="cancelBtn" />-->
    </td>
  </tr>
</table>
{literal}
<SCRIPT language="javascript">
	$(document).ready(function() {
	{/literal}
	  {$callFunction}
	{literal}
  });
{/literal}
</SCRIPT>
</form> 
{include file="footer.tpl"}